﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Markup;
using System.Windows;
using WMSSoft.Lib.Basic;

namespace WMSSoft.WinKStart.Extension
{
    [ContentProperty("ResourceKey")]
    [MarkupExtensionReturnType(typeof(object))]
    public class GetTextXAMLExtension : MarkupExtension
    {
        public string ResourceKey { get; set; }

        public GetTextXAMLExtension()
        {

        }

        public GetTextXAMLExtension(string resourceKey)
        {
            ResourceKey = resourceKey;            
        }

        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            var service = serviceProvider.GetService(typeof(IProvideValueTarget)) as IProvideValueTarget;

            if (service == null)
            {
                return null;
            }

            return LanguageStrings.GetText(ResourceKey);
        }
    }
}
